package com.hjp.designmode.strategy.strategy.impl;

import com.hjp.designmode.strategy.domain.Goods;
import com.hjp.designmode.strategy.domain.impl.Order;
import com.hjp.designmode.strategy.strategy.Strategy;
import com.hjp.designmode.strategy.utils.ArithmeticUtils;


import java.math.BigDecimal;
import java.util.List;

/**
 * @Description:
 * @Author: huangjp6
 * @Date: 2022/3/7 14:22
 */
public class OrdinaryStrategy implements Strategy {

    @Override
    public double countPrice(Order order) {
        double totalPrice = 0.0;
        List<Goods> goodsList = order.getGoodsList();
        for (Goods goods : goodsList) {
            int weight = goods.getWeight();
            double currPrice = goods.getCurrPrice();
            double discount = goods.getDiscount();
            // 保留两位小数
            currPrice = ArithmeticUtils.mul(currPrice, discount, 2) * weight;
            goods.setCurrPrice(currPrice);
            totalPrice = ArithmeticUtils.add(totalPrice, currPrice);
        }
        return totalPrice;
    }
}
